package com.yy.job.console.service;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.yy.job.common.dao.YYJobStepDOMapper;
import com.yy.job.common.dao.po.YYJobLogDO;
import com.yy.job.common.dao.po.YYJobStepDO;
import com.yy.job.common.enums.JobActionEnum;
import com.yy.job.common.enums.JobStepStatusEnum;
import com.yy.job.common.service.impl.YYJobLogServiceImpl;

@Service
public class JobStepConsoleService {
	
	@Autowired
	private YYJobStepDOMapper jobStepDOMapper;
	
	@Autowired
	private YYJobLogServiceImpl yyJobLogServiceImpl;
	
	@Transactional
	public Integer skipStep(YYJobStepDO jobStepDO, String modifier) {
		
		// 增加一条日志
		YYJobLogDO jobLogDO = new YYJobLogDO();
		jobLogDO.setJobId(jobStepDO.getJobId());
		jobLogDO.setJobAction(JobActionEnum.SKIP.getCode());
		jobLogDO.setManualExecUser(modifier);
		jobLogDO.setExecStartTime(new Date());
		jobLogDO.setCreator(modifier);
		jobLogDO.setModifier(modifier);
		yyJobLogServiceImpl.saveSelective(jobLogDO);
		
		YYJobStepDO row = new YYJobStepDO();
		row.setId(jobStepDO.getId());
		row.setStepStatus(JobStepStatusEnum.SKIP.getCode());
		row.setModifier(modifier);
		row.setGmtModified(new Date());
		return jobStepDOMapper.updateByPrimaryKeySelective(row);
	}
	
}
